/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controldepuntos.pantallas;

import controldepuntos.clases.AdministradorVentanas;
import controldepuntos.clases.TcReglamento;
import controldepuntos.clases.TrAlumno;
import controldepuntos.clases.TrUsuario;
import controldepuntos.clases.Utilidades;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author DIANA
 */
public class Alumnos extends javax.swing.JFrame {

    Object idSeleccionado=0;
    int filaSeleccionada=0;
    int id_usuario;
    public Alumnos() {
        initComponents();
        cargaCatalogoAlumno();
    }
    
    public void cargaCatalogoAlumno(){
        try{
            //DefaultTableModel model = new DefaultTableModel();
            DefaultTableModel model = new DefaultTableModel(){ 
            public boolean isCellEditable(int rowIndex,int columnIndex){return false;} };
            TrAlumno trAlumno = new TrAlumno();
            ResultSet rs = trAlumno.getAlumnoListResultSet();
            ResultSetMetaData rsmd = rs.getMetaData();
            int numeroDeColumnas = rsmd.getColumnCount();
            for(int i=1;i<=numeroDeColumnas;i++){
                model.addColumn(rsmd.getColumnLabel(i));
            }
            while(rs.next()){
                Object[] fila = new Object[numeroDeColumnas];
               for(int i=0;i<numeroDeColumnas;i++){
                   fila[i]=rs.getObject(i+1);
               }
               model.addRow(fila);
            }
            tblAlumnos.setModel(model);
            //Ocultar fila Id
            tblAlumnos.getColumnModel().getColumn(0).setMaxWidth(0);
            tblAlumnos.getColumnModel().getColumn(0).setMinWidth(0);
            tblAlumnos.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
            tblAlumnos.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
            
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        
    }
    public boolean validarCampos(){
        try{
            boolean avanzar=true;
            if(txtNombre.getText().isEmpty()){
                JOptionPane.showMessageDialog(this, "El campo Nombre no debe ir vacío. \n Por favor llene este campo","Error",JOptionPane.ERROR_MESSAGE);
                avanzar=false;
            }else{
                    if(txtApPaterno.getText().isEmpty()){
                        JOptionPane.showMessageDialog(this, "El campo Apellido Paterno no debe ir vacío. \n Por favor llene este campo","Error",JOptionPane.ERROR_MESSAGE);
                        avanzar=false;
                    }else{
                        if(Integer.parseInt(txtGrado.getText())==0){
                            JOptionPane.showMessageDialog(this, "El campo Puntaje no debe ir vacío y debe contener solo números. \n Por favor llene este campo","Error",JOptionPane.ERROR_MESSAGE);
                            avanzar=false;
                        }else{
                            if(txtGrupo.getText().isEmpty()){
                                JOptionPane.showMessageDialog(this, "El campo Grupo no debe ir vacío. \n Por favor llene este campo","Error",JOptionPane.ERROR_MESSAGE);
                                avanzar=false;
                            }
                        }
                    }
                
            }
            return avanzar;
        }
        catch(NumberFormatException ex){
            JOptionPane.showMessageDialog(this, "El campo Grado no debe ir vacío y debe contener solo números. \n Por favor llene este campo","Error: "+ex.getMessage(),JOptionPane.ERROR_MESSAGE);
            return false;
        }
        catch(Exception ex){
            JOptionPane.showMessageDialog(this, "Error al validar los campos. \n Por favor contrate al administrador del sistema","Error: "+ex.getMessage(),JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAlumnos = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        txtNumControl = new javax.swing.JTextField();
        txtNombre = new javax.swing.JTextField();
        txtApPaterno = new javax.swing.JTextField();
        txtApMaterno = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtGrado = new javax.swing.JTextField();
        txtGrupo = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        txtNumeroDeControl = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));

        tblAlumnos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tblAlumnos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblAlumnos.setName("tblAlumnos"); // NOI18N
        tblAlumnos.setSelectionBackground(new java.awt.Color(255, 0, 0));
        tblAlumnos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblAlumnosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblAlumnos);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/toga.jpg"))); // NOI18N
        jLabel1.setText("Alumnos");
        jLabel1.setName("lblAlumnos"); // NOI18N

        txtNumControl.setEditable(false);
        txtNumControl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtNumControl.setName("txtNoControl"); // NOI18N

        txtNombre.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtNombre.setName("txtNombre"); // NOI18N
        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });

        txtApPaterno.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtApPaterno.setName("txtAPaterno"); // NOI18N
        txtApPaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApPaternoKeyTyped(evt);
            }
        });

        txtApMaterno.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtApMaterno.setName("txtAMaterno"); // NOI18N
        txtApMaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApMaternoKeyTyped(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Numero de control:");
        jLabel2.setName("lblNoControl"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Nombre:");
        jLabel3.setName("lblNombre"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Apellido Paterno:");
        jLabel4.setName("lblAPaterno"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Apellido Materno:");
        jLabel5.setName("lblAMaterno"); // NOI18N

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/guardar.jpg"))); // NOI18N
        jButton1.setText("Guardar Cambios");
        jButton1.setName("btnGC"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/agregar.jpg"))); // NOI18N
        jButton2.setText("Agregar nuevo");
        jButton2.setName("btnAgregarA"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Grado:");
        jLabel6.setName("lblGrado"); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Grupo:");
        jLabel7.setName("lblGrupo"); // NOI18N

        txtGrado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtGrado.setName("txtGrado"); // NOI18N
        txtGrado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtGradoKeyTyped(evt);
            }
        });

        txtGrupo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtGrupo.setName("txtGrupo"); // NOI18N
        txtGrupo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtGrupoKeyTyped(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton3.setText("MENÚ");
        jButton3.setName("btnSalir"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        txtNumeroDeControl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtNumeroDeControl.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNumeroDeControlKeyTyped(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("Ingrese No. de control:");

        jButton4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/buscar.jpg"))); // NOI18N
        jButton4.setText("Buscar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/bote.jpg"))); // NOI18N
        jButton5.setText("Eliminar Alumno seleccionado");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/LogoSIAPPSuperChico.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jButton2)
                        .addGap(86, 86, 86)
                        .addComponent(jButton5)
                        .addGap(0, 6, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtNumeroDeControl, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton4)))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(5, 5, 5)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING))
                                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                                        .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtNumControl, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                                        .addComponent(txtApPaterno)
                                        .addComponent(txtApMaterno)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(txtGrupo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
                                            .addComponent(txtGrado, javax.swing.GroupLayout.Alignment.LEADING)))))
                            .addGap(63, 63, 63))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton3)
                            .addGap(37, 37, 37)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(233, 233, 233)
                        .addComponent(jLabel10)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel10))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNumControl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(13, 13, 13)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jButton4))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNumeroDeControl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtApPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtApMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtGrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addComponent(jButton1)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton5)
                    .addComponent(jButton3)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        AdministradorVentanas.ocultarPantallaAlumnos();
        AdministradorVentanas.mostrarPantallaMenu();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        AdministradorVentanas.ocultarPantallaAlumnos();
        AdministradorVentanas.pantallaNuevoAlumno=null;
        AdministradorVentanas.mostrarPantallaNuevoAlumno();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void tblAlumnosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblAlumnosMouseClicked
        try{
            filaSeleccionada=this.tblAlumnos.getSelectedRow();
            idSeleccionado=tblAlumnos.getModel().getValueAt(filaSeleccionada, 0);
            //JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnos, idSeleccionado.toString());
            TrAlumno alumnoEncontrado = new TrAlumno();
            alumnoEncontrado = alumnoEncontrado.seleccionarPorId(idSeleccionado.toString());
            id_usuario = alumnoEncontrado.getIdUsuario();
            txtNumControl.setText(alumnoEncontrado.getNumeroDeControl());
            txtNombre.setText(alumnoEncontrado.getNombre());
            txtApPaterno.setText(alumnoEncontrado.getApPaterno());
            txtApMaterno.setText(alumnoEncontrado.getApMaterno());
            txtGrado.setText(String.valueOf(alumnoEncontrado.getGrado()));
            txtGrupo.setText(alumnoEncontrado.getGrupo());
        }catch(Exception ex){
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnos, "Lo sentimos, Ocurrió un error. ARCatalogoFalta.jTable1MouseClicked"+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_tblAlumnosMouseClicked

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        try{
            if(idSeleccionado!=null){
                 if(JOptionPane.showConfirmDialog(AdministradorVentanas.pantallaAlumnos,"¿Está seguro de querer dar de baja al alumno seleccionado?")==JOptionPane.YES_OPTION){
                    TrUsuario usuarioAEliminar = new TrUsuario();
                    TrAlumno alumnoAEliminar = new TrAlumno();
                    alumnoAEliminar.setIdAlumno(Integer.parseInt(idSeleccionado.toString()));
                    alumnoAEliminar.setIdUsuario(id_usuario);
                    usuarioAEliminar.eliminarUsuario(alumnoAEliminar); 
                    alumnoAEliminar.eliminarAlumno(alumnoAEliminar);
                 }
            }
        }catch(Exception ex){
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnos, "Debe seleccionar un elemento de la tabla","Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try{
            if((Integer)idSeleccionado==0){
                JOptionPane.showMessageDialog(this, "Debe seleccionar un elemento de la tabla.","Error",JOptionPane.ERROR_MESSAGE);
            }else{
                if(validarCampos()){
                    TrAlumno alumnoAModificar = new TrAlumno();
                    alumnoAModificar.setNombre(txtNombre.getText());
                    alumnoAModificar.setApPaterno(txtApPaterno.getText());
                    alumnoAModificar.setApMaterno(txtApMaterno.getText());
                    alumnoAModificar.setNumeroDeControl(txtNumControl.getText());
                    alumnoAModificar.setGrado(Integer.parseInt(txtGrado.getText()));
                    alumnoAModificar.setGrupo(txtGrupo.getText());
                    alumnoAModificar.setIdAlumno(Integer.parseInt(idSeleccionado.toString()));
                    alumnoAModificar.modificarAlumno(alumnoAModificar);
                }
            }
        }catch(Exception ex){
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnos, "Los sentimos, ocurrió un error"+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        try{
            if(!txtNumeroDeControl.getText().isEmpty()){
            //El campo de criterio no está vacío. Por lo tanto hacemos la búsqueda.
            DefaultTableModel model = new DefaultTableModel(){ 
            public boolean isCellEditable(int rowIndex,int columnIndex){return false;} };
            TrAlumno trAlumno = new TrAlumno();
            ResultSet rs = trAlumno.buscarAlumnoPorIdNombreResultSet(txtNumeroDeControl.getText());
            ResultSetMetaData rsmd = rs.getMetaData();
            int numeroDeColumnas = rsmd.getColumnCount();
            for(int i=1;i<=numeroDeColumnas;i++){
                model.addColumn(rsmd.getColumnLabel(i));
            }
            while(rs.next()){
                Object[] fila = new Object[numeroDeColumnas];
               for(int i=0;i<numeroDeColumnas;i++){
                   fila[i]=rs.getObject(i+1);
               }
               model.addRow(fila);
            }
            tblAlumnos.setModel(model);
            //Ocultar fila Id
            tblAlumnos.getColumnModel().getColumn(0).setMaxWidth(0);
            tblAlumnos.getColumnModel().getColumn(0).setMinWidth(0);
            tblAlumnos.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
            tblAlumnos.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
            }else{
                //El criterio está vacío. Por lo tanto, buscamos todos los alumnos.
                cargaCatalogoAlumno();
            }
        }catch(Exception ex){
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaAlumnos, "Error: "+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void txtNumeroDeControlKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNumeroDeControlKeyTyped
        Utilidades.establecerLongitudMaxima(txtNumeroDeControl, evt, 14);
    }//GEN-LAST:event_txtNumeroDeControlKeyTyped

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
         Utilidades.establecerLongitudMaxima(txtNombre, evt, 50);
    }//GEN-LAST:event_txtNombreKeyTyped

    private void txtApPaternoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApPaternoKeyTyped
        Utilidades.establecerLongitudMaxima(txtApPaterno, evt, 50);
    }//GEN-LAST:event_txtApPaternoKeyTyped

    private void txtApMaternoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApMaternoKeyTyped
        Utilidades.establecerLongitudMaxima(txtApMaterno, evt, 50);
    }//GEN-LAST:event_txtApMaternoKeyTyped

    private void txtGradoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtGradoKeyTyped
        Utilidades.establecerLongitudMaxima(txtGrado, evt, 1);
    }//GEN-LAST:event_txtGradoKeyTyped

    private void txtGrupoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtGrupoKeyTyped
        Utilidades.establecerLongitudMaxima(txtGrupo, evt, 1);
    }//GEN-LAST:event_txtGrupoKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Alumnos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Alumnos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Alumnos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Alumnos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Alumnos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblAlumnos;
    private javax.swing.JTextField txtApMaterno;
    private javax.swing.JTextField txtApPaterno;
    private javax.swing.JTextField txtGrado;
    private javax.swing.JTextField txtGrupo;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNumControl;
    private javax.swing.JTextField txtNumeroDeControl;
    // End of variables declaration//GEN-END:variables
}
